import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: zm
 * Date: 2023/5/2
 */
public class Demo21 {
    static int N =  100010;
    static int n;
    static int[] a = new int[N],s = new int[N];
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        for(int i = 0; i < n; i++)a[i] = scan.nextInt();

        int res = 0;
        for(int i = 0,j = 0; i < n; i++){
            s[a[i]] ++;
            while(s[a[i]] > 1){
                s[a[j]] --;
                j ++;
            }
            res = Math.max(res,i - j + 1);
        }
        System.out.println(res);
    }
}
